'use strict';

const Jwt = require('jsonwebtoken');

// node -e "console.log(require('crypto').randomBytes(256).toString('base64'));"
// process.env.JWT_SECRET
const secret = process.env.JWT_SECRET || require('crypto').randomBytes(256).toString('base64')
exports.key = secret;
exports.verifyOptions = {
    // urlKey: false,
    cookieKey: false,
    tokenType: 'Bearer'
}
exports.sign = function (obj) {
    return Jwt.sign(obj, secret);
};

exports.validate = function (decoded, request, h) {
    // request.log('debug', decoded)
    if(decoded === '') {
        return { isValid: false }
    } else {
        return { isValid: true };
    }
};
